package com.hae.shop.micoshopportalweb.controller.member;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * 分布式session测试
 */
@Controller
@Slf4j
public class SessionController {

    @Value("${server.port}")
    private String serverPort;

    @RequestMapping("createSession")
    public String createSession(HttpServletRequest httpServletRequest, String value) {
        HttpSession session = httpServletRequest.getSession();
        session.setAttribute("name", value);
        return "success" + serverPort;
    }

    @RequestMapping("getSession")
    public String getSession(HttpServletRequest httpServletRequest) {
        HttpSession session = httpServletRequest.getSession(false);
        Object value = session.getAttribute("name");
        return value + serverPort;
    }
}
